package com.gaogzhen.designPattern.guardedSuspension;

import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.concurrent.TimeUnit;

/**
 * 送信测试
 */
@Slf4j(topic = "d.GuardedTest03")
public class GuardedTest03 {
    public static void main(String[] args) throws InterruptedException {

        // 信件
        HashMap<String, String> mails = new HashMap<>();
        mails.put("101", "你好吗？老朋友");
        mails.put("102", "要买房吗？");
        mails.put("307", "您的快递到了，请签收");
        // 居民房间编号
        String[] identifiers = {"101", "102", "307"};
        // 初始化信箱
        MailBoxes.init(identifiers);
        // 模拟3个居民
        for (String identifier: identifiers) {
            new Thread(new Resident(identifier), "居民" + identifier).start();
        }
        // 模拟3个快递员
        TimeUnit.SECONDS.sleep(1);
        for (String identifier: identifiers) {
            new Thread(new Postman(identifier, mails.get(identifier)), "邮递员" + identifier).start();
        }
    }
}
